package com.uzai.console.service.menuclickmonitor.impl;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.uzai.common.exception.BusinessException;
import com.uzai.common.result.ResponseCode;
import com.uzai.console.common.utils.DateUtil;
import com.uzai.console.dto.menuclickmonitor.MenuClickMonitorDto;
import com.uzai.console.entity.MenuClickMonitor;
import com.uzai.console.mapper.MenuClickMonitorMapper;
import com.uzai.console.service.menuclickmonitor.MenuClickMonitorService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liuqi
 * @date 2021年08月13日 19:49
 */
@Service
public class MenuClickMonitorServiceImpl implements MenuClickMonitorService {

    Logger logger = LoggerFactory.getLogger(MenuClickMonitorServiceImpl.class);

    @Autowired
    private MenuClickMonitorMapper menuClickMonitorMapper;

    /**
     * 保存菜单点击次数
     * @param menuClickMonitorDto
     */
    public void saveMenuClickMonitor(MenuClickMonitorDto menuClickMonitorDto){

        if(menuClickMonitorDto.getMerId() == null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "运营商id不能为空");
        }

        if(StringUtils.isBlank(menuClickMonitorDto.getMenuKey())){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "菜单KEY不能为空");
        }

        if(menuClickMonitorDto.getType() == null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "菜单类型不能为空");
        }

        MenuClickMonitor menuClickMonitor = new MenuClickMonitor();
        menuClickMonitor.setId(IdWorker.getId());
        menuClickMonitor.setMerId(menuClickMonitorDto.getMerId());
        menuClickMonitor.setMenuKey(menuClickMonitorDto.getMenuKey());
        menuClickMonitor.setMenuName(menuClickMonitorDto.getMenuName());
        menuClickMonitor.setType(menuClickMonitorDto.getType());
        menuClickMonitor.setCreateTime(DateUtil.getNowTime());
        menuClickMonitorMapper.insert(menuClickMonitor);
    }

}
